﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Orange.Mvc4App.Models;

namespace Orange.Mvc4App.Services {

    public interface IVenueStaffService : IBaseService<VenueStaff> {
        VenueStaff GetNext();
    }

    public class VenueStaffService : BaseService, IVenueStaffService {
        public IList<VenueStaff> GetList(Func<VenueStaff, bool> filters) {
            if (filters != null)
                return db.VenueStaffs.Where(filters).ToList();
            else
                return db.VenueStaffs.ToList();
        }

        public VenueStaff Find(params object[] keys) {
            return db.VenueStaffs.Find(keys);
        }

        public void Add(VenueStaff model) {
            db.VenueStaffs.Add(model);
        }

        public void Update(VenueStaff model) {
            db.Entry(model).State = EntityState.Modified;
        }

        public void Delete(VenueStaff model) {
            db.VenueStaffs.Remove(model);
        }

        public void Save() {
            db.SaveChanges();
        }

        public void Dispose() {
            db.Dispose();
        }

        public VenueStaff GetNext() {
            int id = 1;
            if (db.VenueStaffs.Count() > 0)
                id = db.VenueStaffs.Max(c => c.Id) + 1;
            return new VenueStaff { Id = id ,Status="A"};
        }
    }
}